package novemberBot.utils;
import novemberBot.FactoryFloorRobot;
import lejos.nxt.Button;
import lejos.nxt.LCD;
import lejos.nxt.Sound;

/**Debugging class can send text or audible debugs
 * @author Antoine Lennartz*/
public class Debugger {
	public static LCDInfo lI;
	public static FactoryFloorRobot robot = FactoryFloorRobot.getInstance();
	public static final int DELAY=10000;
	public static void breakPoint(String s){breakPoint(s, DELAY);}
	
	/**message based debug prints s to LCD and waits for delay ms
	 * @param s - string to be output to LCD
	 * @param delay - miliseconds to  wait for buttonpress b4 resuming lcdi*/
	public static void breakPoint(String s, int delay){
		if(lI!=null)lI.pause();			
		try{
			Sound.playTone(300, 80);
			Thread.sleep(95);
			Sound.playTone(375, 80);
			Thread.sleep(95);
		}catch(Exception e){}
		LCD.clear();
		System.out.println(s);
		Button.waitForPress();
		LCD.clear();
		//robot.pauseMotion(delay);
		if(lI!=null)lI.resume();
	}
	/**Links the lcdi to the debugger so it can pause it when needed
	 * @param lcdI - LCDInfo class used on this brick*/
	public static void setLCDInfo(LCDInfo lcdI){
		lI=lcdI;
	}
	/**Audible debug method
	 * @param freq - frequecy for beep
	 * @param dur - length of beep in ms*/
	public static void audibleDebug(int freq, int dur){
		try{
			Sound.playTone(freq, dur);
			Thread.sleep(dur+10);
		}catch(Exception e){}
	}
	/**fail noise = audible(80, 800)*/
	public static void fail(){
		try{
			Sound.playTone(80, 800);
			Thread.sleep(810);
		}catch(Exception e){}
	}
	/**pauses LCDI so that messages can be printed to screen*/
	public static void pauseLCDI(){
		lI.pause();
	}
	/**resumes LCDI*/
	public static void resumeLCDI(){
		lI.resume();
	}
}
